package sql

import (
	"fmt"
	"strings"
)

type SqlInfo struct {
	SqlType  string
	UserName string
	Password string
	Address  string // ip:port
	DBname   string
}

type Sql interface {
	Select(tableName string, columns []string) (result [][]string, err error)
	Insert(tableName string, columns, args []string) error
	Update(tableName, id string, um map[string]string) error
	Delete(tableName, id string) error
}

func Conn(i *SqlInfo) (sql Sql, err error) {
	switch strings.ToLower(i.SqlType) {
	case "mysql":
		s := &Mysql{}
		err = s.Conn(i)
		if err != nil {
			return
		}
		sql = s
		return
	}
	return nil, fmt.Errorf("未知类型 [%s]", i.SqlType)
}
